package com.wanlian.netty.File.msg.up;

import com.wanlian.File.NetFileInfo;
import com.wanlian.json.JsonStringUtil;
import com.wanlian.netty.File.model.FileHead;
import com.wanlian.netty.File.msg.FileBaseMsg;
import com.wanlian.netty.msg.MsgType;

/**
 * 文件信息
 */
public class FilePeerUpMsg extends FileBaseMsg {

    private FileHead fileHead;

    public FilePeerUpMsg() {
        this.setType(MsgType.DEVICE_FILE_UPLOAD_REQ);
        this.fileHead = new FileHead();
    }

    public FilePeerUpMsg(NetFileInfo netFileInfo) {
        this.setType(MsgType.DEVICE_FILE_UPLOAD_REQ);
        this.fileHead = new FileHead();
        this.fileHead.setSize(netFileInfo.getSize());
        this.fileHead.setFileName(netFileInfo.getFileName());
        this.fileHead.setOffset(netFileInfo.getCurrentIndex());
        this.fileHead.setTotal(netFileInfo.getTotalSize());
        this.fileHead.setFileType(1);
        this.getBaseHead().setClientId(netFileInfo.getFileId());
        this.getBaseHead().setTagClientId("e4aeede5d206801a5a7ef824a0e9c769");
        this.setContent(JsonStringUtil.writeValueAsString(this.fileHead));
        this.setData(netFileInfo.getBytes());
    }
}
